home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / objtba.zip / MMGRRPTS.DOC < prev    next >
Text File  |  1993-01-04  |  43KB  |  1,339 lines

  1.    
  2.    
  3.                                         MMGRRPTS.PAS LISTING  PAGE  1    
  4.    
  5.    
  6.    UNIT MMgrRpts;
  7.    { This unit is the Report generation Unit that supports MMGR.PAS.
  8.      It exists to modularize the program and allow for main program
  9.      code of more than the 65K limit imposed by the TP IDE editor.
  10.      It utilizes routines from both ObjectBase and ObjectInterFace to
  11.      generate the reports and interact with the user.                  }
  12.    
  13.    INTERFACE
  14.    
  15.    USES Dos,
  16.         Crt,
  17.         Utility,     { ObjectInterFace - Various general purpose routines }
  18.                      {                   and interfaces to help system    }
  19.         MMgrVar,     { Global Variable declarations for MMGR.PAS          }
  20.         Forms,       { ObjectInterFace - Form Object Definition           }
  21.         Fields,      { ObjectInterFace - Field Object Definitions         }
  22.         Windows,     { ObjectInterFace - Windows and Menu Definitions     }
  23.         UserIO,      { ObjectInterFace - General User Input Output routines }
  24.         DBObjt,      { ObjectBase      - Lowleve File routines for use by }
  25.                      {                   OopBase Unit                     }
  26.         OopBase;     { ObjectBase      - Contains DB Object Definitions   }
  27.    
  28.    Procedure MailLabels;
  29.    Procedure ContactReports;
  30.    Procedure CompanyReports;
  31.    
  32.    IMPLEMENTATION
  33.    
  34.    function checkforprinter:boolean;
  35.    {  This routine is here for your use.  It informs the user if his printer
  36.       is not contected to the computer or is turned off.  EPSON Specific.   }
  37.    var rgs : registers;
  38.    begin
  39.      with rgs do
  40.      begin
  41.        AX := $0200;
  42.        DX := $0000;
  43.      end;
  44.      intr($17,Rgs);
  45.      CheckForPrinter := not ((Rgs.AH and $C8 = $C8) or (Rgs.AH and $30 = $30));
  46.    end;
  47.    
  48.    Procedure MailLabels;
  49.    var ch : char;  { Dummy variable to receive a keypress so it will be removed
  50.                      from keyboard buffer. }
  51.    
  52.      Procedure ContLabel;
  53.      { Handles Person Based Label generation }
  54.      label NoPrint;
  55.    
  56.      var OldDataFile,
  57.          OldNdxFile,
  58.          FileName: FName;
  59.          LabelDefaults : Form;
  60.          LftMrgn,
  61.          RghtMrgn,    
  62.    
  63.                                         MMGRRPTS.PAS LISTING  PAGE  2    
  64.    
  65.    
  66.          TopMrgn,
  67.          FilterCode,
  68.          PageLength : integer;
  69.          Device: text;
  70.          Tfile: oopfile;
  71.          truncate : Boolean;
  72.          ch : char;
  73.    
  74.         function PassesFilter(c : PersonType; code: integer): Boolean;
  75.         { simple filter routine for Person based label routine }
  76.    
  77.         var passed : Boolean;  { temparary variable }
  78.    
  79.         begin
  80.           Passed := true;
  81.           Case Code of
  82.             2 : begin    { flagged records only }
  83.                   passed := c.flag;
  84.                 end;
  85.             3 : begin    { unflagged records only }
  86.                   passed := not c.flag;
  87.                 end;
  88.           end;
  89.           PassesFilter := Passed;
  90.         end;
  91.    
  92.         Procedure PrintPersonLabel;
  93.         { Prints the Actual label }
  94.    
  95.           Function FormName(L,F,M:string):string;
  96.           { Formats firstname, lastname, middlename fields into an
  97.             acceptable format for a label }
  98.           Var Temp: String;
  99.    
  100.           Begin
  101.             Trim(L);   { Removes trailing blanks from string variable }
  102.             Trim(F);   {  part of ObjectInterFaces general Routines   }
  103.             Trim(M);
  104.             Case F[0] of
  105.               #0 : F := '';                    { Empty }
  106.               #1 : F := Concat(F,'. ');        { Initial - add '. ' }
  107.               Else F := Concat(F,' ');         { Normal  - add space}
  108.             End;
  109.             Case M[0] of
  110.               #0 : M := '';                    { Empty }
  111.               #1 : M := Concat(M,'. ');        { Initial - add '. ' }
  112.               else M := Concat(M,' ');         { Normal  - add space}
  113.             end;
  114.             Temp := concat(F,M,L);
  115.             FormName := Temp;
  116.           end;
  117.    
  118.         begin   {PrintPersonLabel}
  119.           PLine := 1;                     { Global variable in Utiliy Unit }
  120.           while PLine <= topmrgn do
  121.             println(device,0,'');         { ObjectBase - keeps track of print }    
  122.    
  123.                                         MMGRRPTS.PAS LISTING  PAGE  3    
  124.    
  125.    
  126.                                           { head location print line          }
  127.           PrintLn(device,LftMrgn,
  128.                 FormName(Person.LName,Person.FName,Person.MName));
  129.           if Truncate then
  130.              PrintLn(device,LftMrgn,copy(Company.name,1,rghtmrgn-lftmrgn))
  131.           else
  132.              PrintLn(device,LftMrgn,Company.Name);
  133.           PrintLn(device,LftMrgn,Company.addr1);
  134.           if company.addr2[0] > #0 then
  135.              PrintLn(device,LftMrgn,Company.addr2);
  136.           println(device,LftMrgn,concat(trimmed(company.city),', ',Company.st,
  137.                    '   ', Company.Zip));
  138.           while Pline <= Pagelength do PrintLn(device,0,'');
  139.         end;
  140.    
  141.         Procedure TestPrint;
  142.         { Prints a Sample label until position is accepted by user }
  143.    
  144.         Var Choice : Boolean;
  145.    
  146.         Begin
  147.           Choice := False;
  148.           PushHelp(Ord(TestPrintHelp));
  149.           Repeat
  150.             PLine := 1;
  151.             while PLine <= topmrgn do
  152.               println(device,0,'');
  153.           { Printat() Allows you to format printer data similar to screen }
  154.           { if column location requested is less than the current column  }
  155.           { a linefeed is generated and print head is moved to column     }
  156.           { location requested and data is printed on device. PLine is    }
  157.           { handled as expected.       (ObjectInterFace Routine)          }
  158.             Printat(device,LftMrgn,rpt('*',RghtMrgn-LftMrgn));
  159.             if Truncate then
  160.                Printat(device,LftMrgn,rpt('*',RghtMrgn-LftMrgn))
  161.             else
  162.                Printat(device,LftMrgn,rpt('*',sizeof(Company.name)-1));
  163.             Printat(device,LftMrgn,rpt('*',sizeof(Company.addr1)-1));
  164.             Printat(device,LftMrgn,rpt('*',sizeof(Company.addr1)-1));
  165.             println(device,LftMrgn,concat(rpt('*',sizeof(company.city)-1),
  166.                     ', ',rpt('*',sizeof(Company.st)-1),
  167.                      '   ', rpt('*',sizeof(Company.Zip)-1)));
  168.             while Pline <= Pagelength do PrintLn(device,0,'');
  169.             choice := yesno('Is the Label print in the correct position?');
  170.           Until choice;
  171.           PopHelp;
  172.         end;
  173.    
  174.      var TestValue,
  175.          DvcCode : integer;
  176.          m,mf    : MenuArray;    { Defined in WINDOWS Unit - ObjectInterFace }
  177.          ScrnBuf : Pointer;   { if report sent to screen, must put screen    }
  178.                               { somewhere.                                   }
  179.          w       : WindowRecord; { Defined in WINDOWS Unit - ObjectInterFace }
  180.    
  181.      Begin    
  182.    
  183.                                         MMGRRPTS.PAS LISTING  PAGE  4    
  184.    
  185.    
  186.        FillChar(M,SizeOf(M),#0);
  187.        WITH M DO
  188.        BEGIN
  189.          Size := 3;
  190.          Txt[ 0] := 'DESTINATION';
  191.          Txt[ 1] := ' Screen';
  192.          Txt[ 2] := ' Printer';
  193.          Txt[ 3] := ' File';
  194.        END;
  195.        FillChar(Mf,SizeOf(Mf),#0);
  196.        WITH Mf DO
  197.        BEGIN
  198.          Size := 3;
  199.          Txt[ 0] := 'SELECTION';
  200.          Txt[ 1] := ' All';
  201.          Txt[ 2] := ' Selected';
  202.          Txt[ 3] := ' Unselected';
  203.        END;
  204.        testValue := 3;
  205.        LabelDefaults.init(10,8,45,14,2,' Label Defaults ',
  206.                       ' <Ctrl Z> Exits Form ');
  207.        with LabelDefaults do       { Objects are similar to Records }
  208.        begin
  209.          Load(new(PckFldPtr,init(21,2,10,m,'Destination:',@DvcCode)));
  210.       { Conditional field - Only appears if DvcCode = TestValue  }
  211.          Load(new(CndFldPtr,init(@DvcCode,intgr,@TestValue,new(strFldPtr,
  212.                   init(21,3,20,'FileName:','Enter File Name',
  213.                   Rpt('!',20),@FileName)))));
  214.          Load(new(PckFldPtr,init(21,5,10,mf,'Selection:',@FilterCode)));
  215.          load(new(intFldPtr,init(30,7,3,0,65,'TopMargin(Lines):',
  216.                   @TopMrgn)));
  217.          load(new(intfldPtr,init(30,8,3,0,65,'PageLength(Lines):',
  218.                   @pagelength)));
  219.          load(new(IntFldPtr,Init(30,9,3,0,132,'LeftMargin(Chars):',
  220.                   @LftMrgn)));
  221.          load(new(IntFldPtr,Init(30,10,3,0,132,'RightMargin(Chars):',
  222.                   @RghtMrgn)));
  223.        end;
  224.        Pushhelp(Ord(ReportFormhelp));
  225.        DvcCode := 2;
  226.        FileName := 'MAILLBLS.TXT';
  227.        TopMrgn := 1;
  228.        RghtMrgn := 35;
  229.        LftMrgn := 2;
  230.        Pagelength := 6;
  231.        FilterCode := 1;
  232.        Labeldefaults.edit;
  233.        labeldefaults.leave;
  234.        Truncate := ((RghtMrgn - LftMrgn) < (Sizeof(Company.Name)-1));
  235.      { LabelDefaults only gets FileName if Device code points to Disk File }
  236.        Case DvcCode of
  237.          1 : FileName := 'CON';
  238.          2 : begin
  239.                FileName := 'PRN';
  240.                if not checkforprinter then
  241.                begin    
  242.    
  243.                                         MMGRRPTS.PAS LISTING  PAGE  5    
  244.    
  245.    
  246.                  noprintermsg.show;
  247.                  ch := readkey;
  248.                  noprintermsg.hide;
  249.                  goto noprint;
  250.                end;
  251.              end;
  252.        end;
  253.        assign(device,filename);
  254.        rewrite(device);
  255.        if FileName = 'PRN' then
  256.        begin
  257.          SetPrinterMsg.show;
  258.          ch := readKey;
  259.          SetPrinterMsg.hide;
  260.          PrintingMsg.show;
  261.          testprint;
  262.        end
  263.        else if FileName = 'CON' then
  264.          begin
  265.            getmem(ScrnBuf,80*50);
  266.            savewindow(w);
  267.            save_scrn_Rgn(1,1,80,25,ScrnBuf);
  268.            clrscr;
  269.          end;
  270.        with dbase do
  271.        begin
  272.          LoadRelation( PersonData,ContactData,ContactPrsnAccess,
  273.                          @Person.Code);
  274.          LoadRelation( ContactData,CompanyData,CompanySysNdx,
  275.                          @Contact.CompanyCode);
  276.          Switchto(PersonData);
  277.          SetIndex(PersonUserNdx);
  278.          Clear;
  279.          Next;
  280.          Associate(PersonData);
  281.        end;
  282.        While Not dbase.EoFile do
  283.        begin
  284.          If passesfilter(Person,FilterCode) then printPersonlabel;
  285.          dbase.next;
  286.          DBase.Associate(PersonData);
  287.        end;
  288.        If passesfilter(Person,FilterCode) then printPersonlabel;
  289.        if FileName = 'CON' then
  290.        begin
  291.          Gotoxy(1,25);
  292.          Write('Strike a Key to Continue...');
  293.          ch := Readkey;
  294.          Restore_Scrn_Rgn(1,1,80,25,ScrnBuf);
  295.          RestoreWindow(W);
  296.          Freemem(ScrnBuf,80*25*2);
  297.        end;
  298.        Close(Device);
  299.      NoPrint:
  300.        DBase.ClearRelations;
  301.        PrintingMsg.Hide;    
  302.    
  303.                                         MMGRRPTS.PAS LISTING  PAGE  6    
  304.    
  305.    
  306.        LabelDeFaults.done;
  307.        PopHelp;
  308.      End;
  309.    
  310.      Procedure CompanyLabel;
  311.    
  312.      label noprint;
  313.    
  314.      var OldDataFile,
  315.          OldNdxFile,
  316.          FileName: FName;
  317.          LabelDefaults : Form;
  318.          LftMrgn,
  319.          RghtMrgn,
  320.          TopMrgn,
  321.          FilterCode,
  322.          PageLength : integer;
  323.          Device: text;
  324.          Tfile: oopfile;
  325.          truncate : Boolean;
  326.          ch : char;
  327.    
  328.         function PassesFilter(c : CompanyType; code: integer): Boolean;
  329.         var passed : Boolean;
  330.    
  331.         begin
  332.           Passed := true;
  333.           Case Code of
  334.             2 : begin    { flagged records only }
  335.                   passed := c.flag;
  336.                 end;
  337.             3 : begin    { unflagged records only }
  338.                   passed := not c.flag;
  339.                 end;
  340.           end;
  341.           PassesFilter := Passed;
  342.         end;
  343.    
  344.         procedure printCompanyLabel;
  345.         begin
  346.           PLine := 1;
  347.           while PLine <= topmrgn do
  348.             println(device,0,'');
  349.           if Truncate then
  350.              PrintLn(device,LftMrgn,copy(Company.name,1,rghtmrgn-lftmrgn))
  351.           else
  352.              PrintLn(device,LftMrgn,Company.Name);
  353.           PrintLn(device,LftMrgn,Company.addr1);
  354.           if company.addr2[0] > #0 then
  355.              PrintLn(device,LftMrgn,Company.addr2);
  356.           println(device,LftMrgn,concat(trimmed(company.city),', ',Company.st,
  357.                    '   ', Company.Zip));
  358.           while Pline <= Pagelength do PrintLn(device,0,'');
  359.         end;
  360.    
  361.         procedure testprint;    
  362.    
  363.                                         MMGRRPTS.PAS LISTING  PAGE  7    
  364.    
  365.    
  366.    
  367.         var choice : boolean;
  368.    
  369.         begin
  370.           Choice := False;
  371.           PushHelp(ord(TestPrintHelp));
  372.           Repeat
  373.             PLine := 1;
  374.             while PLine <= topmrgn do
  375.               println(device,0,'');
  376.             if Truncate then
  377.                Printat(device,LftMrgn,rpt('*',RghtMrgn-LftMrgn))
  378.             else
  379.                Printat(device,LftMrgn,rpt('*',sizeof(Company.name)-1));
  380.             Printat(device,LftMrgn,rpt('*',sizeof(Company.addr1)-1));
  381.             Printat(device,LftMrgn,rpt('*',sizeof(Company.addr1)-1));
  382.             println(device,LftMrgn,concat(rpt('*',sizeof(company.city)-1),
  383.                     ', ',rpt('*',sizeof(Company.st)-1),
  384.                      '   ', rpt('*',sizeof(Company.Zip)-1)));
  385.             while Pline <= Pagelength do PrintLn(device,0,'');
  386.             choice := yesno('Is the Label print in the correct position?');
  387.           Until choice;
  388.           PopHelp;
  389.         end;
  390.    
  391.      var TestValue,
  392.          DvcCode : integer;
  393.          m,mf    : MenuArray;
  394.          ScrnBuf : Pointer;
  395.          w       : WindowRecord;
  396.    
  397.      Begin
  398.        FillChar(M,SizeOf(M),#0);
  399.        WITH M DO
  400.        BEGIN
  401.          Size := 3;
  402.          Txt[ 0] := 'DESTINATION';
  403.          Txt[ 1] := ' Screen';
  404.          Txt[ 2] := ' Printer';
  405.          Txt[ 3] := ' File';
  406.        END;
  407.        FillChar(Mf,SizeOf(Mf),#0);
  408.        WITH Mf DO
  409.        BEGIN
  410.          Size := 3;
  411.          Txt[ 0] := 'SELECTION';
  412.          Txt[ 1] := ' All';
  413.          Txt[ 2] := ' Flagged';
  414.          Txt[ 3] := ' Unflagged';
  415.        END;
  416.        testValue := 3;
  417.        LabelDefaults.init(10,8,45,14,2,' Label Defaults ','');
  418.        with LabelDefaults do
  419.        begin
  420.          Load(new(PckFldPtr,init(21,2,10,m,'Destination:',@DvcCode)));
  421.          Load(new(CndFldPtr,init(@DvcCode,intgr,@TestValue,new(strFldPtr,    
  422.    
  423.                                         MMGRRPTS.PAS LISTING  PAGE  8    
  424.    
  425.    
  426.                   init(21,3,20,'FileName:','Enter File Name',
  427.                   Rpt('!',20),@FileName)))));
  428.          Load(new(PckFldPtr,init(21,5,10,mf,'Selection:',@FilterCode)));
  429.          load(new(intFldPtr,init(30,7,3,0,65,'TopMargin(Lines):',
  430.                   @TopMrgn)));
  431.          load(new(intfldPtr,init(30,8,3,0,65,'PageLength(Lines):',
  432.                   @pagelength)));
  433.          load(new(IntFldPtr,Init(30,9,3,0,132,'LeftMargin(Chars):',
  434.                   @LftMrgn)));
  435.          load(new(IntFldPtr,Init(30,10,3,0,132,'RightMargin(Chars):',
  436.                   @RghtMrgn)));
  437.        end;
  438.        Truncate := ((RghtMrgn - LftMrgn) < (Sizeof(Company.Name)-1));
  439.        DvcCode := 2;
  440.        FileName := 'MAILLBLS.TXT';
  441.        TopMrgn := 1;
  442.        RghtMrgn := 35;
  443.        LftMrgn := 2;
  444.        Pagelength := 6;
  445.        FilterCode := 1;
  446.        PushHelp(Ord(ReportFormHelp));
  447.        Labeldefaults.edit;
  448.        labeldefaults.leave;
  449.        Case DvcCode of
  450.          1 : FileName := 'CON';
  451.          2 : begin
  452.                FileName := 'PRN';
  453.                if not checkforprinter then
  454.                begin
  455.                  noprintermsg.show;
  456.                  ch := readkey;
  457.                  noprintermsg.hide;
  458.                  goto noprint;
  459.                end;
  460.              end;
  461.        end;
  462.        assign(device,filename);
  463.        rewrite(device);
  464.        if FileName = 'PRN' then
  465.        begin
  466.          SetPrinterMsg.show;
  467.          ch := readKey;
  468.          SetPrinterMsg.hide;
  469.          PrintingMsg.show;
  470.          testprint;
  471.        end
  472.        else if FileName = 'CON' then
  473.          begin
  474.            getmem(ScrnBuf,80*50);
  475.            savewindow(w);
  476.            save_scrn_Rgn(1,1,80,25,ScrnBuf);
  477.            clrscr;
  478.          end;
  479.        with dbase do
  480.        begin
  481.          SwitchTo(CompanyData);    
  482.    
  483.                                         MMGRRPTS.PAS LISTING  PAGE  9    
  484.    
  485.    
  486.          SetIndex(CompanyUserNdx);
  487.          Clear;
  488.          Next;
  489.        end;
  490.        While Not dbase.EoFile do
  491.        begin
  492.          If passesfilter(Company,FilterCode) then printcompanylabel;
  493.          dbase.next;
  494.        end;
  495.        If passesfilter(Company,FilterCode) then printcompanylabel;
  496.        if FileName = 'CON' then
  497.        begin
  498.          Gotoxy(1,25);
  499.          Write('Strike a Key to Continue...');
  500.          ch := Readkey;
  501.          Restore_Scrn_Rgn(1,1,80,25,ScrnBuf);
  502.          RestoreWindow(W);
  503.          Freemem(ScrnBuf,80*25*2);
  504.        end;
  505.        PrintingMsg.Hide;
  506.        Close(Device);
  507.      NoPrint:
  508.        LabelDeFaults.done;
  509.        PopHelp;
  510.      End;
  511.    
  512.    var
  513.        choice : integer;
  514.        Finished : Boolean;
  515.    begin
  516.      pushhelp(ord(labelhelp));
  517.      Finished := False;
  518.      Repeat
  519.        Choice := labelsMenu.Pop;
  520.        LabelsMenu.Leave;
  521.        CASE Choice of
  522.          1 : contlabel;
  523.          2 : Companylabel;
  524.          3 : Finished := True;
  525.        End;
  526.      Until Finished;
  527.      LabelsMenu.Hide;
  528.      pophelp;
  529.    end;
  530.    
  531.    Procedure comp_W_Contacts;
  532.    label NoPrint;
  533.    var
  534.        choice : integer;
  535.        ch : char;
  536.        Another_Contact : Boolean;
  537.        Title,
  538.        Device,
  539.        OldCode : string;
  540.        delimstrt,
  541.        delimfnsh  : string[2];    
  542.    
  543.                                         MMGRRPTS.PAS LISTING  PAGE  10   
  544.    
  545.    
  546.        Dest   : Text;
  547.        scrn   : array[1..2000] of word;
  548.        w      : windowrecord;
  549.        i,
  550.        colpos,
  551.        tfiletype,
  552.        PageNo,
  553.        PageLength : integer;
  554.        m : menuarray;
  555.        fn     : form;
  556.    
  557.      Procedure DispCwCntBlock;
  558.    
  559.        Procedure DispContact;
  560.        begin
  561.          PrintAt(Dest,LeftMargin+31,
  562.                  concat(trimmed(person.LName),', ',trimmed(person.FName),' ',
  563.                  trimmed(person.MName)));
  564.          Printat(Dest,RightMargin-sizeof(Contact.Position),
  565.                       concat(delimstrt,Trimmed(Contact.Position),delimfnsh));
  566.        end;
  567.    
  568.      begin
  569.          another_contact := True;
  570.        { print next PLine }
  571.          IF (PLine >= PageLength - BottomMargin) and (PageLength > -1) then
  572.          begin
  573.          { Print Header }
  574.            if PageNo > 0 then formfeed(Dest,Device);
  575.            PLine := 0;
  576.            While PLine < TopMargin do
  577.              PrintLn(Dest,0,'');
  578.            Inc(PageNo);
  579.            PrintAt(Dest,LeftMargin,DateStr(Today,mmddyyyy));
  580.            PrintAt(Dest,((RightMargin-Length(title)) div 2), Title);
  581.            PrintLn(dest,RightMargin-8,concat('Page ',i_str(PageNo,3)));
  582.            PrintLn(Dest,0,'');
  583.            PrintAt(dest,LeftMargin,'COMPANY');
  584.            PrintLn(Dest,LeftMargin+31,
  585.            'CONTACT');
  586.            PrintLn(dest,LeftMargin, rpt('-',RightMargin-LeftMargin));
  587.          end;
  588.        { Print company name }
  589.          Printat(Dest,LeftMargin,copy(Company.Name,1,28));
  590.        { Print contact name and position }
  591.          DispContact;
  592.          DBase.NextAssoc(CompanyData);
  593.          if OldCode = Person.Code then another_Contact := False;
  594.        { NewLine }
  595.          println(dest,0,'');
  596.        { Print Company address 1 }
  597.          Printat(Dest,LeftMargin,Company.Addr1);
  598.          If another_contact then
  599.          begin
  600.            DispContact;
  601.            DBase.NextAssoc(CompanyData);    
  602.    
  603.                                         MMGRRPTS.PAS LISTING  PAGE  11   
  604.    
  605.    
  606.            if OldCode = Person.Code then another_Contact := False;
  607.          end;
  608.        { NewLine }
  609.          println(dest,0,'');
  610.          If Company.addr2 <> '' then
  611.          begin
  612.            Printat(Dest,LeftMargin,Company.Addr2);
  613.            If another_contact then
  614.            begin
  615.              DispContact;
  616.              DBase.NextAssoc(CompanyData);
  617.              if OldCode = Person.Code then another_Contact := False;
  618.            end;
  619.          { NewLine }
  620.            println(dest,0,'');
  621.          end;
  622.        { print company city st zip }
  623.          Printat(Dest,LeftMargin,
  624.                  concat(Company.City,', ',Company.St,'  ',
  625.                         Formatted(ZipMask,Company.zip)));
  626.          If another_contact then
  627.          begin
  628.            DispContact;
  629.            DBase.NextAssoc(CompanyData);
  630.            if OldCode = Person.Code then another_Contact := False;
  631.          end;
  632.          println(Dest,0,'');
  633.        { Print company Phone }
  634.          PrintAt(Dest,LeftMargin,
  635.                  formatted(phnMask,company.phone));
  636.          While another_contact do
  637.          begin
  638.            DispContact;
  639.            DBase.NextAssoc(CompanyData);
  640.            if OldCode = Person.Code then another_Contact := False;
  641.          end;
  642.    
  643.        { NewLine }
  644.          println(dest,0,'');
  645.          println(dest,0,'');
  646.      end;
  647.    
  648.      Procedure PrintCwCntBlock;
  649.    
  650.        procedure PrintContact;
  651.        begin
  652.          If another_contact then
  653.          begin
  654.            PrintAt(Dest,LeftMargin+SizeOf(Company.Name)+Length(PhnMask)+1,
  655.                    concat(person.LName,', ',person.FName,' ',person.MName));
  656.            Printat(Dest,RightMargin-sizeof(Contact.Position),
  657.                         concat(delimstrt,Trimmed(Contact.Position),delimfnsh));
  658.            DBase.NextAssoc(CompanyData);
  659.            if OldCode = Person.Code then another_Contact := False;
  660.          end;
  661.        end;    
  662.    
  663.                                         MMGRRPTS.PAS LISTING  PAGE  12   
  664.    
  665.    
  666.    
  667.      begin
  668.          another_contact := True;
  669.        { print next PLine }
  670.          IF (PLine >= PageLength - BottomMargin) and (PageLength > -1) then
  671.          begin
  672.          { Print Header }
  673.            if PageNo > 0 then formfeed(Dest,Device);
  674.            PLine := 0;
  675.            While PLine < TopMargin do
  676.              PrintLn(Dest,0,'');
  677.            Inc(PageNo);
  678.            PrintAt(Dest,LeftMargin,DateStr(Today,mmddyyyy));
  679.            PrintAt(Dest,((RightMargin-Length(title)) div 2), Title);
  680.            PrintLn(dest,RightMargin-8,concat('Page ',i_str(PageNo,3)));
  681.            PrintLn(Dest,0,'');
  682.            PrintAt(dest,LeftMargin,'COMPANY');
  683.            PrintAt(Dest,LeftMargin+SizeOf(Company.Name),'PHONE');
  684.            PrintAt(Dest,LeftMargin+SizeOf(Company.Name)+Length(PhnMask)+1,
  685.            'CONTACT');
  686.            PrintLn(Dest,RightMargin-sizeof(Contact.Position),'POSITION');
  687.            PrintLn(dest,LeftMargin, rpt('-',RightMargin-LeftMargin));
  688.          end;
  689.        { Print company name }
  690.          Printat(Dest,LeftMargin,Company.Name);
  691.        { Print company Phone }
  692.          PrintAt(Dest,LeftMargin+SizeOf(Company.Name),
  693.                  formatted(phnMask,company.phone));
  694.        { Print contact name and position }
  695.          PrintContact;
  696.        { NewLine }
  697.          println(dest,0,'');
  698.        { Print Company address 1 }
  699.          Printat(Dest,LeftMargin,Company.Addr1);
  700.          PrintContact;
  701.        { NewLine }
  702.          println(dest,0,'');
  703.          If Company.addr2 <> '' then
  704.          begin
  705.            Printat(Dest,LeftMargin,Company.Addr2);
  706.            printcontact;
  707.          { NewLine }
  708.            println(dest,0,'');
  709.          end;
  710.        { print company city st zip }
  711.          Printat(Dest,LeftMargin,
  712.                  concat(Company.City,', ',Company.St,'  ',
  713.                         Formatted(ZipMask,Company.zip)));
  714.          while another_contact do PrintContact;
  715.        { NewLine }
  716.          println(dest,0,'');
  717.          println(dest,0,'');
  718.      end;
  719.    
  720.    begin
  721.      another_Contact := true;    
  722.    
  723.                                         MMGRRPTS.PAS LISTING  PAGE  13   
  724.    
  725.    
  726.      pushhelp(ord(reporthelp));
  727.      Choice := DeviceMenu.Pop;
  728.      delimstrt := '';
  729.      delimfnsh := '';
  730.      tfiletype := 0;
  731.      DeviceMenu.Hide;
  732.      CASE Choice of
  733.        1 : begin
  734.              Device      := 'CON';
  735.              LeftMargin  :=  0;
  736.              rightmargin := 79;
  737.              topmargin   :=  0;
  738.              Bottommargin:=  4;
  739.              pagelength  := 24;
  740.              savewindow(w);
  741.              save_Scrn_Rgn(1,1,80,25,@scrn);
  742.              clrscr;
  743.            end;
  744.        2 : begin
  745.              Device      := 'PRN';
  746.              if not checkforprinter then
  747.              begin
  748.                 noprintermsg.show;
  749.                 ch := readkey;
  750.                 noprintermsg.hide;
  751.                 goto noprint;
  752.              end;
  753.              LeftMargin  :=  5;
  754.              RightMargin := 120;
  755.              topmargin   :=  2;
  756.              Bottommargin:=  7;
  757.              PageLength  := 66;
  758.              SetPrinterMsg.show;
  759.              ch := readKey;
  760.              SetPrinterMsg.hide;
  761.              PrintingMsg.show;
  762.            end;
  763.        3 : begin
  764.              Device      := 'REPORT.PRN';
  765.              fn.init(20,8,40,6,QueryBorder,' FILE NAME ','');
  766.              fn.Load(new(strfldptr,init(13,2,25,'Path + Name:',
  767.              'Enter Path & Name of File',rpt('!',25),@Device)));
  768.              fn.edit;
  769.              fn.hide;
  770.              fn.done;
  771.              delimstrt := '';
  772.              delimfnsh := '';
  773.              LeftMargin  :=  5;
  774.              RightMargin := 125;
  775.              topmargin   :=  2;
  776.              Bottommargin:=  7;
  777.              PageLength  := 66;
  778.              ff          := concat(#12);
  779.              PrintingMsg.show;
  780.            end;
  781.        4 : begin    
  782.    
  783.                                         MMGRRPTS.PAS LISTING  PAGE  14   
  784.    
  785.    
  786.             PopHelp;
  787.             exit;
  788.            end;
  789.      End;
  790.      assign(Dest,device);
  791.      rewrite(dest);
  792.      PLine := PageLength + 1;
  793.      if device = 'PRN' then write(Dest,#15);
  794.      PCol := 0;
  795.      DBase.LoadRelation( CompanyData,ContactData,ContactCompAccess,
  796.                          @Company.Code);
  797.      DBase.loadRelation( ContactData,PersonData,PersonSysNdx,
  798.                          @Contact.personCode);
  799.      DBase.Switchto(CompanyData);
  800.      DBase.SetIndex(CompanyUserNdx);
  801.      dbase.top;
  802.      DBase.Associate(CompanyData);
  803.      OldCode := Person.Code;
  804.      Title := '**** C O M P A N Y   L I S T I N G ****';
  805.      PageNo := 0;
  806.      while Not DBase.EoFile DO
  807.      begin
  808.        if Device = 'CON' then
  809.          DispCwCntBlock
  810.        else
  811.          PrintCwCntBlock;
  812.        DBase.Next;
  813.        DBase.Associate(CompanyData);
  814.        OldCode := Person.Code;
  815.      end;
  816.      if Device = 'CON' then
  817.        DispCwCntBlock
  818.      else
  819.        PrintCwCntBlock;
  820.    { NewLine }
  821.      println(dest,0,'');
  822.      formfeed(dest,Device);
  823.      if Device = 'CON'then
  824.      begin
  825.        restore_Scrn_Rgn(1,1,80,25,@scrn);
  826.        RestoreWindow(w);
  827.      end
  828.      else
  829.        printingmsg.hide;
  830.      close(dest);
  831.      DBase.ClearRelations;
  832.    Noprint:
  833.      pophelp;
  834.    end;
  835.    
  836.    
  837.    Procedure Comp_WO_Contacts;
  838.    var
  839.        FileName: FName;
  840.        LabelDefaults : Form;
  841.        LftMrgn,    
  842.    
  843.                                         MMGRRPTS.PAS LISTING  PAGE  15   
  844.    
  845.    
  846.        RghtMrgn,
  847.        BtmMrgn,
  848.        TopMrgn,
  849.        PageNo,
  850.        FilterCode,
  851.        PageLength : integer;
  852.        Title : String;
  853.        Device: text;
  854.        ToPrint: Boolean;
  855.    
  856.       function PassesFilter(c : CompanyType; code: integer): Boolean;
  857.       var passed : Boolean;
  858.    
  859.       begin
  860.         Passed := true;
  861.         Case Code of
  862.           2 : begin    { flagged records only }
  863.                 passed := c.flag;
  864.               end;
  865.           3 : begin    { unflagged records only }
  866.                 passed := not c.flag;
  867.               end;
  868.         end;
  869.         PassesFilter := Passed;
  870.       end;
  871.    
  872.       procedure NewPage;
  873.       VAR CH: CHAR;
  874.       begin
  875.          if ToPrint then
  876.          begin
  877.            if PageNo > 0 then formfeed(Device,FileName);
  878.            PLine := 0;
  879.            While PLine < TopMrgn do
  880.              PrintLn(Device,0,'');
  881.            Inc(PageNo);
  882.            PrintAt(Device,LftMrgn,DateStr(Today,mmddyyyy));
  883.            PrintAt(Device,((RghtMrgn-Length(title)) div 2), Title);
  884.            PrintLn(Device,RghtMrgn-8,concat('Page ',i_str(PageNo,3)));
  885.            PrintLn(Device,0,'');
  886.            PrintAt(Device,LftMrgn,'COMPANY NAME');
  887.            PrintAt(Device,LftMrgn+SizeOf(Company.Name),'ADDRESS');
  888.            PrintAt(Device,LftMrgn+SizeOf(Company.Name) + SizeOf(Company.Addr1),
  889.                    'CITY / ST / ZIP');
  890.            PrintLn(Device,LftMrgn,'PHONE');
  891.            PrintLn(Device,LftMrgn, rpt('-',RghtMrgn-LftMrgn));
  892.          end
  893.          else
  894.          begin
  895.            If PageNo > 0 then
  896.            begin
  897.              GotoXY(1,25);
  898.              Write('Press any Key to Continue...');
  899.              ch := ReadKey;
  900.              clrscr;
  901.            end;    
  902.    
  903.                                         MMGRRPTS.PAS LISTING  PAGE  16   
  904.    
  905.    
  906.            PLine := 0;
  907.            Inc(PageNo);
  908.            PrintAt(Device,LftMrgn,DateStr(Today,mmddyyyy));
  909.            PrintAt(Device,((RghtMrgn-Length(title)) div 2), Title);
  910.            PrintLn(Device,RghtMrgn-8,concat('Page ',i_str(PageNo,3)));
  911.            PrintLn(Device,0,'');
  912.            PrintAt(Device,LftMrgn,'COMPANY NAME');
  913.            Println(Device,LftMrgn+SizeOf(Company.Name),'CITY');
  914.            PrintAt(Device,LftMrgn,'ADDRESS');
  915.            Println(Device,LftMrgn+SizeOf(Company.Name),'STATE / ZIP');
  916.            PrintLn(Device,LftMrgn+SizeOf(Company.Name),'PHONE');
  917.            PrintLn(Device,LftMrgn, rpt('-',RghtMrgn-LftMrgn));
  918.          end;
  919.       end;
  920.    
  921.       procedure PrintCompanyLine;
  922.       begin
  923.         if toPrint then
  924.         begin
  925.           if PLine > PageLength - BtmMrgn then newpage;
  926.           Printat(device,LftMrgn,Company.name);
  927.           Printat(device,LftMrgn+sizeof(company.name),Company.addr1);
  928.           Printat(device,LftMrgn+Sizeof(Company.name)+sizeof(company.addr1),
  929.                   concat(trimmed(company.city),', ',
  930.                   company.st,'  ',trimmed(company.zip)));
  931.           printat(device,LftMrgn,formatted('(999)999-99999',company.phone));
  932.           Printat(device,LftMrgn+sizeof(company.name),Company.addr2);
  933.         end
  934.         else
  935.         begin
  936.           if PLine > PageLength - BtmMrgn then newpage;
  937.           Printat(device,LftMrgn,Company.name);
  938.           PrintLn(device,LftMrgn+sizeof(company.name),Company.City);
  939.           Printat(device,LftMrgn,Company.addr1);
  940.           PrintLn(device,LftMrgn+sizeof(company.name),concat(Company.St,
  941.                          ' ',Company.zip));
  942.           Printat(device,LftMrgn,Company.Addr2);
  943.           printLn(device,LftMrgn+sizeof(company.name),
  944.                   formatted('(999)999-99999',company.phone));
  945.           PrintLn(Device,0,'');
  946.         end;
  947.       end;
  948.    
  949.    label noprint;
  950.    
  951.    var TestValue,
  952.        DvcCode : integer;
  953.        m,mf    : MenuArray;
  954.        ch      : Char;
  955.        ScrnBuf : Pointer;
  956.        w       : WindowRecord;
  957.    
  958.    Begin
  959.      FillChar(M,SizeOf(M),#0);
  960.      WITH M DO
  961.      BEGIN    
  962.    
  963.                                         MMGRRPTS.PAS LISTING  PAGE  17   
  964.    
  965.    
  966.        Size := 3;
  967.        Txt[ 0] := 'DESTINATION';
  968.        Txt[ 1] := ' Screen';
  969.        Txt[ 2] := ' Printer';
  970.        Txt[ 3] := ' File';
  971.      END;
  972.      FillChar(Mf,SizeOf(Mf),#0);
  973.      WITH Mf DO
  974.      BEGIN
  975.        Size := 3;
  976.        Txt[ 0] := 'SELECTION';
  977.        Txt[ 1] := ' All';
  978.        Txt[ 2] := ' Flagged';
  979.        Txt[ 3] := ' Unflagged';
  980.      END;
  981.      testValue := 3;
  982.      LabelDefaults.init(10,8,45,14,2,' Label Defaults ','');
  983.      with LabelDefaults do
  984.      begin
  985.        Load(new(PckFldPtr,init(21,2,10,m,'Destination:',@DvcCode)));
  986.        Load(new(CndFldPtr,init(@DvcCode,intgr,@TestValue,new(strFldPtr,
  987.                 init(21,3,20,'FileName:','Enter File Name',
  988.                 Rpt('!',20),@FileName)))));
  989.        Load(new(PckFldPtr,init(21,5,10,mf,'Selection:',@FilterCode)));
  990.        load(new(intFldPtr,init(30,7,3,0,5,'TopMargin(Lines):',
  991.                 @TopMrgn)));
  992.        load(new(intfldPtr,init(30,8,3,0,66,'PageLength(Lines):',
  993.                 @pagelength)));
  994.        load(new(IntFldPtr,Init(30,9,3,0,132,'Line Width(Chars):',
  995.                 @RghtMrgn)));
  996.      end;
  997.      PushHelp(Ord(ReportFormHelp));
  998.      DvcCode := 2;
  999.      FileName := 'COMPRPT.TXT';
  1000.      BtmMrgn := 3;
  1001.      PageNo := 0;
  1002.      TopMrgn := 1;
  1003.      RghtMrgn := 80;
  1004.      LftMrgn := 5;
  1005.      Pagelength := 66;
  1006.      FilterCode := 1;
  1007.      Title := '*** C O M P A N Y   L I S T ***';
  1008.      ToPrint := True;
  1009.      Labeldefaults.edit;
  1010.      labeldefaults.leave;
  1011.      Case DvcCode of
  1012.        1 : begin
  1013.              FileName := 'CON';
  1014.            end;
  1015.        2 : Begin
  1016.              FileName := 'PRN';
  1017.              if not checkforprinter then
  1018.              begin
  1019.                noprintermsg.show;
  1020.                ch := readkey;
  1021.                noprintermsg.hide;    
  1022.    
  1023.                                         MMGRRPTS.PAS LISTING  PAGE  18   
  1024.    
  1025.    
  1026.                goto noprint;
  1027.              end;
  1028.            end;
  1029.      end;
  1030.      assign(device,filename);
  1031.      rewrite(device);
  1032.      if FileName = 'PRN' then
  1033.      begin
  1034.        SetPrinterMsg.show;
  1035.        ch := readKey;
  1036.        SetPrinterMsg.hide;
  1037.        PrintingMsg.show;
  1038.        if rghtmrgn < 120 then
  1039.        BEGIN
  1040.          RGHTMRGN := LftMrgn + SizeOf(Company.Name) +
  1041.                      SizeOf(Company.addr1) + SizeOf(Company.St) +
  1042.                      SizeOf(Company.City) + SizeOf(Company.Zip) + 4;
  1043.          write(device,#15);
  1044.        END;
  1045.      end
  1046.      else if FileName = 'CON' then
  1047.        begin
  1048.          getmem(ScrnBuf,80*50);
  1049.          savewindow(w);
  1050.          save_scrn_Rgn(1,1,80,25,ScrnBuf);
  1051.          clrscr;
  1052.          LftMrgn := 0;
  1053.          RghtMrgn := 79;
  1054.          PageLength := 24;
  1055.          BtmMrgn := 2;
  1056.          ToPrint := False;
  1057.        end;
  1058.      with dbase do
  1059.      begin
  1060.        SwitchTo(CompanyData);
  1061.        SetIndex(CompanyUserNdx);
  1062.        Clear;
  1063.        Next;
  1064.      end;
  1065.      Pline := PageLength +1;
  1066.      While Not dbase.EoFile do
  1067.      begin
  1068.        If passesfilter(Company,FilterCode) then PrintCompanyLine;
  1069.        dbase.next;
  1070.      end;
  1071.      If passesfilter(Company,FilterCode) then PrintCompanyLine;
  1072.      if FileName = 'CON' then
  1073.      begin
  1074.        Gotoxy(1,25);
  1075.        Write('Strike a Key to Continue...');
  1076.        ch := Readkey;
  1077.        Restore_Scrn_Rgn(1,1,80,25,ScrnBuf);
  1078.        RestoreWindow(W);
  1079.        Freemem(ScrnBuf,80*25*2);
  1080.      end
  1081.      else formfeed(device,filename);    
  1082.    
  1083.                                         MMGRRPTS.PAS LISTING  PAGE  19   
  1084.    
  1085.    
  1086.      PrintingMsg.Hide;
  1087.      close(Device);
  1088.    NoPrint:
  1089.      LabelDeFaults.done;
  1090.      PopHelp;
  1091.    end;
  1092.    
  1093.    
  1094.    Procedure CompanyReports;
  1095.    
  1096.    var ch : char;
  1097.        choice : integer;
  1098.        Finished : Boolean;
  1099.    begin
  1100.      pushhelp(ord(reporthelp));
  1101.      Finished := False;
  1102.      Repeat
  1103.        Choice := CompLstMenu.Pop;
  1104.        CompLstMenu.Leave;
  1105.        CASE Choice of
  1106.          1 : begin
  1107.                comp_W_Contacts;
  1108.              end;
  1109.          2 : begin
  1110.                comp_WO_Contacts
  1111.              end;
  1112.          3 : Finished := True;
  1113.        End;
  1114.      Until Finished;
  1115.      CompLstMenu.Hide;
  1116.      pophelp;
  1117.    end;
  1118.    
  1119.    Procedure ContactReports;
  1120.    Label NoPrint;
  1121.    var
  1122.        choice : integer;
  1123.        ch : char;
  1124.        NewPerson : Boolean;
  1125.        Title,
  1126.        Device,
  1127.        OldCode : string;
  1128.        delimstrt,
  1129.        delimfnsh  : string[2];
  1130.        Dest   : Text;
  1131.        scrn   : array[1..2000] of word;
  1132.        w      : windowrecord;
  1133.        i,
  1134.        colpos,
  1135.        tfiletype,
  1136.        PageNo,
  1137.        PageLength : integer;
  1138.        m : menuarray;
  1139.        fn     : form;
  1140.    
  1141.    begin    
  1142.    
  1143.                                         MMGRRPTS.PAS LISTING  PAGE  20   
  1144.    
  1145.    
  1146.      pushhelp(ord(reporthelp));
  1147.      Choice := DeviceMenu.Pop;
  1148.      delimstrt := '';
  1149.      delimfnsh := '';
  1150.      tfiletype := 0;
  1151.      DeviceMenu.Hide;
  1152.      CASE Choice of
  1153.        1 : begin
  1154.              Device      := 'CON';
  1155.              LeftMargin  :=  0;
  1156.              rightmargin := 79;
  1157.              topmargin   :=  0;
  1158.              Bottommargin:=  0;
  1159.              pagelength  := 24;
  1160.              savewindow(w);
  1161.              save_Scrn_Rgn(1,1,80,25,@scrn);
  1162.              clrscr;
  1163.            end;
  1164.        2 : begin
  1165.              Device      := 'PRN';
  1166.              if not checkforprinter then
  1167.              begin
  1168.                 noprintermsg.show;
  1169.                 ch := readkey;
  1170.                 noprintermsg.hide;
  1171.                 goto noprint;
  1172.              end;
  1173.              LeftMargin  :=  1;
  1174.              RightMargin := 79;
  1175.              topmargin   :=  2;
  1176.              Bottommargin:=  2;
  1177.              PageLength  := 66;
  1178.              SetPrinterMsg.show;
  1179.              ch := readKey;
  1180.              SetPrinterMsg.hide;
  1181.              PrintingMsg.show;
  1182.            end;
  1183.        3 : begin
  1184.              Device      := 'REPORT.PRN';
  1185.              fn.init(20,8,40,7,QueryBorder,' FILE NAME ','');
  1186.              fn.load(new(StrFldPtr,init(11,2,25,'FileName:',
  1187.               'Enter path & file to save report to ...',rpt('!',25),@Device)));
  1188.              WITH M DO
  1189.              BEGIN
  1190.                Size := 4;
  1191.                Txt[ 0] := 'SELECT';
  1192.                Txt[ 1] := ' 1 Print File';
  1193.                Txt[ 2] := ' 2 Comma Delimited';
  1194.                Txt[ 3] := ' 3 Quote Delimited';
  1195.                Txt[ 4] := ' 4 Quote+Comma';
  1196.              END;
  1197.              fn.load(new(PckFldPtr,init(11,3,15,m,'Format:',@tfiletype)));
  1198.              fn.edit;
  1199.              fn.hide;
  1200.              fn.done;
  1201.              Case tfileType of    
  1202.    
  1203.                                         MMGRRPTS.PAS LISTING  PAGE  21   
  1204.    
  1205.    
  1206.                1 : begin
  1207.                      delimstrt := '';
  1208.                      delimfnsh := '';
  1209.                      LeftMargin  :=  1;
  1210.                      RightMargin := 79;
  1211.                      topmargin   :=  2;
  1212.                      Bottommargin:=  2;
  1213.                      PageLength  := 66;
  1214.                      ff          := concat(#12);
  1215.                    end;
  1216.                2 : begin
  1217.                      delimstrt := '';
  1218.                      delimfnsh := ',';
  1219.                      LeftMargin  :=  0;
  1220.                      RightMargin :=  0;
  1221.                      topmargin   :=  0;
  1222.                      Bottommargin:= -1;
  1223.                      PageLength  := -1;
  1224.                      ff          := '';
  1225.                    end;
  1226.                3 : begin
  1227.                      delimstrt := '"';
  1228.                      delimfnsh := '"';
  1229.                      LeftMargin  :=  0;
  1230.                      RightMargin :=  0;
  1231.                      topmargin   :=  0;
  1232.                      Bottommargin:= -1;
  1233.                      PageLength  := -1;
  1234.                      ff          := '';
  1235.                    end;
  1236.                4 : begin
  1237.                      delimstrt := '"';
  1238.                      delimfnsh := '",';
  1239.                      LeftMargin  :=  0;
  1240.                      RightMargin :=  0;
  1241.                      topmargin   :=  0;
  1242.                      Bottommargin:= -1;
  1243.                      PageLength  := -1;
  1244.                      ff          := '';
  1245.                    end;
  1246.              end;
  1247.              PrintingMsg.show;
  1248.            end;
  1249.        4 : begin
  1250.             PopHelp;
  1251.             exit;
  1252.            end;
  1253.      End;
  1254.      assign(Dest,device);
  1255.      rewrite(dest);
  1256.      PLine := PageLength + 1;
  1257.      PCol := 0;
  1258.      DBase.LoadRelation( PersonData,ContactData,ContactPrsnAccess,
  1259.                          @Person.Code);
  1260.      DBase.loadRelation( ContactData,CompanyData,CompanySysNdx,
  1261.                          @Contact.CompanyCode);    
  1262.    
  1263.                                         MMGRRPTS.PAS LISTING  PAGE  22   
  1264.    
  1265.    
  1266.      DBase.Switchto(PersonData);
  1267.      DBase.SetIndex(PersonUserNdx);
  1268.      dbase.top;
  1269.      DBase.Associate(PersonData);
  1270.      OldCode := Company.Code;
  1271.      Title := '**** C O N T A C T   L I S T ****';
  1272.      PageNo := 0;
  1273.      NewPerson := True;
  1274.      while NOT DBase.EoFile DO
  1275.      begin
  1276.      { print next PLine }
  1277.        IF (PLine >= PageLength - BottomMargin) and (PageLength > -1) then
  1278.        begin
  1279.        { Print Header }
  1280.          if PageNo > 0 then formfeed(Dest,Device);
  1281.          PLine := 0;
  1282.          While PLine < TopMargin do
  1283.            PrintLn(Dest,0,'');
  1284.          Inc(PageNo);
  1285.          PrintAt(Dest,LeftMargin,DateStr(Today,mmddyyyy));
  1286.          PrintAt(Dest,((RightMargin-Length(title)) div 2), Title);
  1287.          PrintLn(dest,RightMargin-8,concat('Page ',i_str(PageNo,3)));
  1288.          PrintLn(Dest,0,'');
  1289.          PrintAt(dest,LeftMargin,'CONTACT');
  1290.          PrintAt(Dest,LeftMargin+25,'COMPANY');
  1291.          PrintLn(Dest,RightMargin-sizeof(Contact.Position),'POSITION');
  1292.          PrintLn(dest,LeftMargin, rpt('-',RightMargin-LeftMargin));
  1293.        end;
  1294.        If (NewPerson) or (PageLength = -1) then
  1295.          Printat(Dest,Leftmargin,concat(DelimStrt,Trimmed(Person.LName),', ',
  1296.          Trimmed(Person.FName),' ',Trimmed(Person.MName),Delimfnsh));
  1297.        if tfiletype>1 then colpos := 0 else colpos := 25;
  1298.        Printat(Dest,LeftMargin+colpos,concat(delimstrt,Company.Name,delimfnsh));
  1299.        Printat(Dest,RightMargin-sizeof(Contact.Position),
  1300.                     concat(delimstrt,Trimmed(Contact.Position),delimfnsh));
  1301.        println(dest,0,'');
  1302.      { reset data }
  1303.        NewPerson := False;
  1304.        DBase.NextAssoc(PersonData);
  1305.        if Company.Code = OldCode then
  1306.        begin
  1307.          DBase.Next;
  1308.          DBase.Associate(PersonData);
  1309.          OldCode := Company.Code;
  1310.          NewPerson := True;
  1311.        end;
  1312.      end;
  1313.      If (NewPerson) or (PageLength = -1) then
  1314.        Printat(Dest,Leftmargin,concat(DelimStrt,Trimmed(Person.LName),', ',
  1315.        Trimmed(Person.FName),' ',Trimmed(Person.MName),Delimfnsh));
  1316.      if tfiletype>1 then colpos := 0 else colpos := 25;
  1317.      Printat(Dest,LeftMargin+colpos,concat(delimstrt,Company.Name,delimfnsh));
  1318.      Printat(Dest,RightMargin-sizeof(Contact.Position),
  1319.                   concat(delimstrt,Trimmed(Contact.Position),delimfnsh));
  1320.      println(dest,0,'');
  1321.      formfeed(dest,Device);    
  1322.    
  1323.                                         MMGRRPTS.PAS LISTING  PAGE  23   
  1324.    
  1325.    
  1326.      if Device = 'CON'then
  1327.      begin
  1328.        restore_Scrn_Rgn(1,1,80,25,@scrn);
  1329.        RestoreWindow(w);
  1330.      end
  1331.      else
  1332.        printingmsg.hide;
  1333.      close(dest);
  1334.      DBase.ClearRelations;
  1335.    NoPrint:
  1336.      pophelp;
  1337.    end;
  1338.    
  1339.    end. { Unit MMgrRpts }